#ifndef NAVIGATIONWIDGET_H
#define NAVIGATIONWIDGET_H

#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
#include <QScrollArea>
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QStyledItemDelegate>

class ArrowItemDelegate : public QStyledItemDelegate
{
    Q_OBJECT
public:
    ArrowItemDelegate(QObject *parent = nullptr);
    ~ArrowItemDelegate();

    void paint(QPainter *painter, const QStyleOptionViewItem &option,
               const QModelIndex &index) const override;
};

class NavigationWidget : public QWidget
{
    Q_OBJECT

public:
    explicit NavigationWidget(QWidget *parent = nullptr);
    ~NavigationWidget();

    // 公共接口
    void setSelectedItem(const QString &stoveName, const QString &pageName = "");
    void setSelectedItemByIndex(int stoveIndex, int pageIndex = 0);
    void addstove(const QString &stoveName);
    void clearNavigationItems();
    
    // 获取当前选中的项目
    QString getCurrentstove() const;
    QString getCurrentPage() const;

signals:
    void navigationItemClickedByIndex(int stoveIndex, int pageIndex);
    void stoveExpanded(const QString &stoveName);

protected:
    void paintEvent(QPaintEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;

private slots:
    void onNavigationItemClicked(QTreeWidgetItem *item, int column);
    void onItemExpanded(QTreeWidgetItem *item);
    void onItemCollapsed(QTreeWidgetItem *item);

private:
    void setupUI();
    void setupConnections();
    void createstoveItem(const QString &stoveName);
    void createPageItem(QTreeWidgetItem *parent, const QString &pageName);
    QTreeWidgetItem* findstoveItem(const QString &stoveName);
    
    // 布局组件
    QVBoxLayout *m_mainLayout;
    
    // 导航栏组件
    QScrollArea *m_scrollArea;
    QTreeWidget *m_navigationTree;
    
    // 当前选中的项目
    QString m_currentstove;
    QString m_currentPage;
    
    // 样式常量
    static const QString stove_COLOR;
    static const QString PAGE_COLOR;
    static const QString SELECTED_COLOR;
    static const QString HOVER_COLOR;
};

#endif // NAVIGATIONWIDGET_H
